const koa = require('koa-router')
const m = require("koa-multer")
const fs = require("fs")

const {avatar,avatarInfo,bgavatar,bgimginfo,handlefile,getfilename,downloadfile,deletefile}  = require("../controller/file")
const file = new koa
const avatarUpload = m({
   dest: "./uploads/avatar"
 });
const avatarHandler = avatarUpload.single('avatar');
const bgavatarHandler = avatarUpload.single('bgavatar');

const fileUpload = m({
  dest:"./file/bgfile"
})  
const fileindo = fileUpload.single('file');

//获取 用户头像请求 
file.post('/avatar', avatarHandler,avatar)
file.get('/:userId/avatar',avatarInfo)


//用户封面上传 
file.post("bg/avatar",bgavatarHandler,bgavatar)
file.get('/:userId/bgavatar',bgimginfo)

//大文件上传 
file.post("/file",fileindo,handlefile)
//文件名称
file.get('/:userid/filename',getfilename)
//文件下载
file.get('/:filename/:userid/download',downloadfile)
//文件删除
file.delete('/deletefile',deletefile)




module.exports = file;